import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

export interface TencentCloudConfig {
  cos: {
    secretId: string;
    secretKey: string;
    bucket: string;
    region: string;
  };
}

export interface AppConfig {
  port: number;
  database: {
    url: string;
  };
  jwt: {
    secret: string;
    expiresIn: string;
  };
  google: {
    clientId: string;
  };
  tencentCloud: TencentCloudConfig;
  environment: string;
  isDevelopment: boolean;
  isProduction: boolean;
}

@Injectable()
export class AppConfigService {
  constructor(private readonly configService: ConfigService<AppConfig>) {}

  get port(): number {
    return this.configService.get<number>('port', 3000);
  }

  get database() {
    return this.configService.get('database');
  }

  get jwt() {
    return this.configService.get('jwt');
  }

  get google() {
    return this.configService.get('google');
  }

  get tencentCloud() {
    return this.configService.get('tencentCloud');
  }

  get environment(): string {
    return this.configService.get<string>('environment', 'development');
  }

  get isDevelopment(): boolean {
    return this.configService.get<boolean>('isDevelopment', false);
  }

  get isProduction(): boolean {
    return this.configService.get<boolean>('isProduction', false);
  }

  /**
   * 检查腾讯云COS配置是否完整
   */
  isTencentCloudConfigured(): boolean {
    const cos = this.tencentCloud?.cos;
    return !!(cos?.secretId && cos?.secretKey && cos?.bucket && cos?.region);
  }

  /**
   * 获取腾讯云COS配置
   */
  getTencentCloudConfig(): TencentCloudConfig['cos'] | null {
    if (!this.isTencentCloudConfigured()) {
      return null;
    }
    return this.tencentCloud?.cos || null;
  }
} 